/*
 * @Author: Jiraiya
 * @Date: 2020-03-02 17:44:20
 * @LastEditors: Jiraiya
 * @LastEditTime: 2020-03-02 18:39:40
 * @Description: 
 */

//🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

//类数组转数组

console.log(Array.from('hello'))
//[ 'h', 'e', 'l', 'l', 'o' ]

function f(a, b, c){
    console.log(Array.from(arguments))
}
f(1, 2, 3) //[ 1, 2, 3 ]

console.log(Array.from({
    '0': 'a',
    '1': 'b',
    '2': 'c',
    length: 3
})) //[ 'a', 'b', 'c' ]


// 一组数转数组

console.log(Array.of(1, 2, 3))
// [ 1, 2, 3 ]


// 复制数组
const a = ['a', 'b', 'c']
console.log(a.copyWithin(0, 2, 3))
// [ 'c', 'b', 'c' ]

//查找数组中的值

// find没查到就返回undefined
const a = [1, 2, 3]
console.log(a.find(val => val > 1)) //2
// findIndex查找返回下标 没有-1
console.log(a.findIndex(val => val > 1)) //1


//fill填充数组
console.log(['a', 'b', 'c'].fill(1, 0, 3))
//[ 1, 1, 1 ]


// keys values entries
const arr = ['a', 'b', 'c']
for(let [val, idx] of arr.entries()){
    console.log(val, idx)
}
// 0 'a'
// 1 'b'
// 2 'c'

// includes同String.prototype.includes

console.log([NaN].includes(NaN)) // true
console.log([NaN].indexOf(NaN)) // -1

//展开数组
const a = [[1, [2, [3]]]]
console.log(a.flat(Infinity))
//[1, 2, 3]

const a = [1, 2, 3]
console.log(a.flatMap(x => [x, x * 2]))
//[1, 2, 2, 4, 3, 6]